/**   
* Filename:    BaseService.java   
* Create at:   2016年2月26日 下午5:34:20   
* Description:  
* Modification History:   
* Author      Version     Description   
* ----------------------------------------------------------------- 
* Garfield      1.0       1.0 Version   
*/ 
package com.taotao.manage.service;

import java.util.List;

import com.github.abel533.mapper.Mapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.manage.pojo.BasePojo;

public abstract class BaseService<T extends BasePojo> {
	/**
	 * 需要类实现  返回具体的Mapper
	 */
	private Mapper<T> mapper;
	
	public abstract Mapper<T> getMapper();
	
	/**
	 * 根据主键ID查询
	 * Title: queryById
	 * Description:
	 * @author puguoan 
	 * @param id
	 * @return
	 */
	public T queryById(Long id){
		return mapper.selectByPrimaryKey(id);
	}
	
	/**
	 * 查询list
	 * Title: queryList
	 * Description:
	 * @author puguoan 
	 * @param t
	 * @return
	 */
	public List<T> queryList(T t){
		return getMapper().select(t);
	}
	
	/**
	 * 分页查询
	 * Title: queryListPage
	 * Description:
	 * @author puguoan 
	 * @param t
	 * @param page
	 * @param rows
	 * @return
	 */
	public PageInfo<T> queryListPage(T t,Integer page,Integer rows){
		//设置分页参数
		PageHelper.startPage(page, rows);
		
		List<T> list = this.queryList(t);
		return new PageInfo<T>(list);
	}
	
	/**
	 * 查询总数量
	 * Title: queryCount
	 * Description:
	 * @author puguoan 
	 * @param t
	 * @return
	 */
	public Integer queryCount(T t){
		return this.getMapper().selectCount(t);
	}
	
	/**
	 * 添加数据
	 * Title: save
	 * Description:
	 * @author puguoan 
	 * @param t
	 * @return
	 */
	public Integer save(T t){
		return this.getMapper().insert(t);
	}
	/**
	 * 新增  不为null数据插入
	 * Title: saveSelective
	 * Description:
	 * @author puguoan 
	 * @param t
	 * @return
	 */
	public Integer saveSelective(T t){
		return this.getMapper().insertSelective(t);
	}
	
	/**
	 * 更新
	 * Title: update
	 * Description:
	 * @author puguoan 
	 * @param t
	 * @return
	 */
	public Integer update(T t){
		return this.getMapper().updateByPrimaryKey(t);
	}
	/**
	 * 更新  null不管
	 * Title: updateSelective
	 * Description:
	 * @author puguoan 
	 * @param t
	 * @return
	 */
	public Integer updateSelective(T t){
		return this.getMapper().updateByPrimaryKeySelective(t);
	}
	
	/**
	 * 删除
	 * Title: deleteById
	 * Description:
	 * @author puguoan 
	 * @param id
	 * @return
	 */
	public Integer deleteById(Long id){
		return this.getMapper().deleteByPrimaryKey(id);
	}
}


    